<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>添加供应商</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<link rel="stylesheet" href="admin/css/common.css" type="text/css" />
<link rel="stylesheet" href="admin/css/provider.css" type="text/css" />
<script type="text/javascript" src="admin/js/province-city.js"></script>
<script type="text/javascript" src="js/jquery-1.7.1.js"></script>
<script type="text/javascript" src="js/jwidget_1.0.0-min.js"></script>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=1.3"></script>
<script type="text/javascript">
	var GPSPoint;
	var s = [ "s1", "s2" ];
	var opt0 = [ "省份", "地级市" ];
	function setup() {
		for (i = 0; i < s.length - 1; i++)
			document.getElementById(s[i]).onchange = new Function("change("
					+ (i + 1) + ")");
		change(0);

		var t = new Date();
		var y = t.getFullYear();
		for (i = 1900; i <= y; i++)
			document.getElementById("year_select").options.add(new Option(""
					+ i, i));
		for (i = 1; i <= 12; i++)
			document.getElementById("month_select").options.add(new Option(""
					+ i, i));
	}

	function regionChange() {
		var currentIndex = document.getElementById("s0").selectedIndex;
		if (currentIndex == 0) {
			setup();
			//alert("0");
		}
		if (currentIndex == 1) {

			document.getElementById("s1").options.length = 0;
			document.getElementById("s1").options.add(new Option("海外", "海外"));
			document.getElementById("s1").onchange = function() {
				returnValue = false;
			}

			document.getElementById("s2").options.length = 0;
			document.getElementById("s2").options.add(new Option("海外", "海外"));
			document.getElementById("s2").onchange = function() {
				returnValue = false;
			}
			//alert("1");
		}
	}

	function checkName() {
		if ($("#name").val() != "") {
			var params = {
				providerName : $("#name").val(),
				flag : "add"
			};
			jQuery.post("checkNameExist.action", params, callbackFunc, "json");
		}
	}
	function callbackFunc(data) {
		if (data.existFlag > 0) {
			$('#nameTip').html('<font color="red">*名字已经存在</font>');
			$('#nameFlag').val("no");
		} else {
			$('#nameTip').html('<font color="green">名字可以使用</font>');
			$('#nameFlag').val("yes");
		}
	}

	//邮箱判断正则表达式
	function isEmail(yx) {
		if (yx == "")
			return true;
		var reyx = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;
		return (reyx.test(yx));
	}

	//判断是否为空
	function check() {

		$('#nameTip').text("");
		$('#shortableTip').text("");
		$('#sTip').text("");
		$('#addressTip').text("");
		$('#registercapitalTip').text("");
		$('#staffsizeTip').text("");
		$('#factoryareaTip').text("");
		$('#bigslabTip').text("");
		$('#rawStoneTip').text("");
		$('#standardslabTip').text("");
		$('#phoneTip').text("");
		$('#faxTip').text("");
		$('#emailTip').text("");

		var phoneflag = 0;
		var phonestring = "";
		$('.phone').each(function() {
			if (isNaN($(this).val()) == true)
				phoneflag = 0;
			else if ($(this).val() != "")
				phonestring += $(this).val() + "#";
		});

		var faxflag = 0;
		var faxstring = "";
		$('.fax').each(function() {
			if (isNaN($(this).val()))
				faxflag = 1;
			else if ($(this).val() != "")
				faxstring += $(this).val() + "#";
		});

		var emailflag = 0;
		var emailstring = "";
		$('.email').each(function() {
			if (!isEmail($(this).val()))
				emailflag = 1;
			else if ($(this).val() != "")
				emailstring += $(this).val() + "#";
		});

		var websitestring = "";
		$('.website').each(function() {
			if ($(this).val() != "")
				websitestring += $(this).val() + "#";
		});

		if ($('#name').val() == "") {
			$('#nameTip').text("*名字不能为空");
			$('#name').focus();
			return false;
		} else if (phoneflag == 1) {
			$('#phoneTip').text("*电话应为数字");
			$('#phone').focus();
			return false;
		} else if (faxflag == 1) {
			$('#faxTip').text("*传真应为数字");
			$('#fax').focus();
			return false;
		} else if (emailflag == 1) {
			$('#emailTip').text("*邮箱格式不正确");
			$('#email').focus();
			return false;
		} else if ($('#nameFlag').val() != "yes") {
			$('#nameTip').text("*名字已经存在");
			$('#name').focus();
			return false;
		} else if ($('#shortable').val() == "") {
			$('#shortableTip').text("*缩写不能为空");
			$('#shortable').focus();
			return false;
		} else if ($('#s1').val() == "省份" || $('#s2').val() == "地级市") {
			$('#sTip').text("*请选择好省、市");
			$('#s1').focus();
			return false;
		} else if ($('#address').val() == "") {
			$('#addressTip').text("*地址不能为空");
			$('#address').focus();
			return false;
		} else if (isNaN($('#registerCapital').val())) {
			$('#registercapitalTip').text("*注册资金应为数字");
			$('#registerCapital').focus();
			return false;
		} else if (isNaN($('#staffSize').val())) {
			$('#staffsizeTip').text("*人员规模应为数字");
			$('#staffSize').focus();
			return false;
		} else if (isNaN($('#factoryArea').val())) {
			$('#factoryareaTip').text("*厂房面积应为数字");
			$('#factoryArea').focus();
			return false;
		} else if (isNaN($('#bigSlab').val())) {
			$('#bigslabTip').text("*应为数字");
			$('#bigSlab').focus();
			return false;
		} else if (isNaN($('#rawStone').val())) {
			$('#rawstoneTip').text("*应为数字");
			$('#rawStone').focus();
			return false;
		} else if (isNaN($('#standardSlab').val())) {
			$('#standardslabTip').text("*应为数字");
			$('#standardSlab').focus();
			return false;
		} else {
			//检查图片
			var fileext = document.getElementById("iconFile").value.substring(
					document.getElementById("iconFile").value.lastIndexOf("."),
					document.getElementById("iconFile").value.length);
			fileext = fileext.toLowerCase();
			if ((fileext != '.jpg') && (fileext != '.gif')
					&& (fileext != '.jpeg') && (fileext != '.png')
					&& (fileext != '.bmp')) {
				alert("对不起，系统仅支持标准格式的照片，请您调整格式后重新上传，谢谢 !");
				$('#iconFile').focus();
				return false;
			} else {
				$('#iconFileName').val(fileext);
			}
		}

		$('#td_phone')
				.append(
						"<input type=\"text\" style=\"display:none\" name=\"provider.phone\" value=\""+ phonestring + "\"/>");
		$('#td_fax')
				.append(
						"<input type=\"text\" style=\"display:none\" name=\"provider.fax\" value=\""+ faxstring + "\"/>");
		$('#td_email')
				.append(
						"<input type=\"text\" style=\"display:none\" name=\"provider.email\" value=\""+ emailstring + "\"/>");
		$('#td_website')
				.append(
						"<input type=\"text\" style=\"display:none\" name=\"provider.webSite\" value=\""+ websitestring + "\"/>");
		return true;
	}

	function addPhone() {
		$('#td_phone').append("<input type=\"text\" class=\"phone\" />");
		$('#but_phone').remove();
		$('#phoneTip').remove();
		$('#td_phone')
				.append(
						"<input id=\"but_phone\" type=\"button\" value=\"添加\" onclick=addPhone()></input><span class=\"tip\" id=\"phoneTip\"></span>");
	}
	function addFax() {
		$('#td_fax').append("<input type=\"text\" class=\"fax\" />");
		$('#but_fax').remove();
		$('#faxTip').remove();
		$('#td_fax')
				.append(
						"<input id=\"but_fax\" type=\"button\" value=\"添加\" onclick=addFax()></input><span class=\"tip\" id=\"faxTip\"></span>");
	}
	function addWebsite() {
		$('#td_website').append("<input type=\"text\" class=\"website\" />");
		$('#but_website').remove();
		$('#websiteTip').remove();
		$('#td_website')
				.append(
						"<input id=\"but_website\" type=\"button\" value=\"添加\" onclick=addWebsite()></input><span class=\"tip\" id=\"websiteTip\"></span>");
	}
	function addEmail() {
		$('#td_email').append("<input type=\"text\" class=\"email\" />");
		$('#but_email').remove();
		$('#emailTip').remove();
		$('#td_email')
				.append(
						"<input id=\"but_email\" type=\"button\" value=\"添加\" onclick=addEmail()></input><span class=\"tip\" id=\"emailTip\"></span>");
	}

	function addMap() {
		$('#map_tr').css("display", "block");
		$('#gps_address').val("重置坐标");
		$('#lnglat').val("");
		loadMap();
	}

	function loadMap() {
		map = new BMap.Map("container");
		//默认中心
		var point = new BMap.Point(118.18267822265625, 24.781747337815794)
		map.centerAndZoom(point, 8);
		map.addControl(new BMap.NavigationControl());//启动鱼骨插件
		map.addControl(new BMap.OverviewMapControl());//启动缩略图
		map.enableScrollWheelZoom(); // 启用滚轮放大缩小。
		map.enableKeyboard(); // 启用键盘操作。
		var marker = new BMap.Marker(point);
		map.addOverlay(marker);
		marker.enableDragging(true); // 设置标注可拖拽

		marker.addEventListener("dragend", function() {
			GPSPoint = marker.getPosition();
			var GPS = GPSPoint.lng + "，" + GPSPoint.lat;
			$('#lnglat').val(GPS);
		});

	}
</script>
</head>
<body onload="setup()">
	<div id="provider_zone">
		<form action="provider/saveProvider.action" method="post"
			enctype="multipart/form-data" onsubmit="return check();">
			<table width="99%" border="0" align="center" cellpadding="3"
				cellspacing="1" class="table_style">
				<tr>
					<td width="18%" class="left_title_1">供应商照片</td>
					<td width="82%"><input type="file" class="input-file"
						name="iconFile" id="iconFile"> <input type="hidden"
						id="iconFileName" name="iconFileName">
					</td>
				</tr>
				<tr>
					<td class="left_title_2">供应商名称</td>
					<td><input type="text" name="provider.name" id="name"
						onblur="checkName()" /> <span class="tip" id="nameTip"></span> <input
						type="hidden" id="nameFlag" value="no" />
					</td>
				</tr>
				<tr>
					<td class="left_title_1">检索缩写</td>
					<td><input type="text" name="provider.shortable"
						id="shortable" maxlength="1" /> <span class="tip"
						id="shortableTip"></span>
					</td>
				</tr>
				<tr>
					<td class="left_title_2">省、市</td>
					<td><select id="s0" name="provider.region" class="address"
						onchange="regionChange()">
							<option>中国</option>
							<option>海外</option>
					</select> <select id="s1" name="provider.province" class="address"><option>省份</option>
					</select> <select id="s2" name="provider.city" class="address"><option>地级市</option>
					</select> <span class="tip" id="sTip"></span>
					</td>
				</tr>
				<tr>
					<td class="left_title_1">公司地址</td>
					<td><input class="long-input" type="text"
						name="provider.address" id="address" /><input id="gps_address"
						style="background:#ffffff;color:#73938e; border:0;cursor:hand;"
						type="button" value="在地图上标识" onclick=addMap()></input> <span
						class="tip" id="addressTip"></span>
					</td>
				</tr>
				<tr style="display:none;" id="map_tr">
					<td class="left_title_1">地图定位</td>
					<td>
						<div>
							<span>经纬度：</span> <input name="provider.lnglat"
								style="background:#ffffff;color:#73938e; border:0;"
								class="long-input" type="text" id="lnglat" readonly="true" />
						</div>
						<div>
							<span class="tip">请将标注拖曳至公司所在位置</span>
						</div>
						<div style="width:500px;height:400px;border:1px solid gray;"
							id="container"></div></td>
				</tr>
				<tr>
					<td class="left_title_2">注册资金</td>
					<td><input type="text" name="provider.registerCapital"
						id="registerCapital" /><span>万元</span><span class="tip"
						id="registercapitalTip"></span>
					</td>
				</tr>
				<tr>
					<td class="left_title_1">成立时间</td>
					<td><select id="year_select" name="year" class="address"></select>年
						<select id="month_select" name="month" class="address"></select>月</td>
					<!-- <td><input type="text" name="provider.foundationTime"
						id="foundationTime" /></td> -->
				</tr>
				<tr>
					<td class="left_title_2">人员规模</td>
					<td><input type="text" name="provider.staffSize"
						id="staffSize" /><span>人</span><span class="tip"
						id="staffsizeTip"></span>
					</td>
				</tr>
				<tr>
					<td class="left_title_1">厂房面积</td>
					<td><input type="text" name="provider.factoryArea"
						id="factoryArea" /><span>平方米</span><span class="tip"
						id="factoryareaTip"></span>
					</td>
				</tr>
				<tr>
					<td class="left_title_2">加工设备</td>
					<td><input type="text" name="provider.equipment"
						id="equipment" />
					</td>
				</tr>
				<tr>
					<td class="left_title_1" rowspan="3">年加工能力</td>
					<td><span>大板&nbsp;&nbsp;&nbsp;</span> <input type="text"
						name="provider.bigSlab" id="bigSlab" /> <span>平方米</span><span
						class="tip" id="bigslabTip"></span>
					</td>
				</tr>
				<tr>
					<td><span>荒料&nbsp;&nbsp;&nbsp;</span> <input type="text"
						name="provider.rawStone" id="rawStone" /> <span>平方米</span><span
						class="tip" id="rawstoneTip"></span>
					</td>
				</tr>
				<tr>
					<td><span>规格板</span> <input type="text"
						name="provider.standardSlab" id="standardSlab" /> <span>平方米</span><span
						class="tip" id="standardslabTip"></span>
					</td>
				</tr>
				<tr>
					<td class="left_title_2" rowspan="6">联系方式</td>
					<td><span>联系人</span> <input type="text"
						name="provider.contactPerson" id="contactPerson" />
					</td>
				</tr>
				<tr>
					<td><span>职务&nbsp;&nbsp;&nbsp;</span> <input type="text"
						name="provider.duty" id="duty" /></td>
				</tr>
				<tr>
					<td id='td_phone'><span>电话&nbsp;&nbsp;&nbsp;</span> <input
						type="text" id="phone" class="phone" /><input id="but_phone"
						type="button" value="添加" onclick=addPhone()></input> <span
						class="tip" id="phoneTip"></span></td>
				</tr>
				<tr>
					<td id='td_fax'><span>传真&nbsp;&nbsp;&nbsp;</span> <input
						type="text" id="fax" class="fax" /><input id="but_fax"
						type="button" value="添加" onclick=addFax()></input><span
						class="tip" id="faxTip"></span></td>
				</tr>
				<tr>
					<td id='td_website'><span>网址&nbsp;&nbsp;&nbsp;</span> <input
						type="text" id="website" class="website" /><input
						id="but_website" type="button" value="添加" onclick=addWebsite()></input><span
						class="tip" id="websiteTip"></span></td>
				</tr>
				<tr>
					<td id='td_email'><span>邮箱&nbsp;&nbsp;&nbsp;</span> <input
						type="text" id="email" class="email" /><input id="but_email"
						type="button" value="添加" onclick=addEmail()></input><span
						class="tip" id="emailTip"></span></td>
				</tr>
				<tr>
					<td class="left_title_1">概要介绍</td>
					<td><input class="long-input" type="text"
						name="provider.shortDescription" id="shortDescription"></td>
				</tr>
				<tr>
					<td class="left_title_2">主营业务</td>
					<td><input class="long-input" type="text"
						name="provider.product" id="product" />
					</td>
				</tr>
				<tr>
					<td class="left_title_1">其他介绍（获奖情况等）</td>
					<td><input class="long-input" type="text"
						name="provider.other" id="other" />
					</td>
				</tr>
				<tr>
					<td colspan="2" style="padding-left: 560px;"><input
						type="submit" class="input-submit" value="保存，下一步">
					</td>
				</tr>
			</table>
		</form>
	</div>
</body>
</html>
